from flask import jsonify, make_response


class Response:
    @staticmethod
    def json_response(data):
        return make_response(jsonify(data))

    @classmethod
    def success(cls, code=1000, msg="请求成功", data=None, **kwargs):
        data = {
            "code": code,
            "msg": msg,
            "data": data
        }
        data.update(kwargs)
        return cls.json_response(data)

    @classmethod
    def error(cls, code=1001, msg="请求失败", data=None, **kwargs):
        data = {
            "code": code,
            "msg": msg,
            "data": data
        }
        data.update(kwargs)
        return cls.json_response(data)
